﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xilium.CefGlue;
using System.Windows.Forms;

namespace IanWebkitBrowser
{
    class ProcessControllerV8Handler : CefV8Handler
    {

        public ProcessControllerV8Handler()
        {
        }

        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            switch (name)
            {
                case "Init":
                    IanBrowser.ObjectForScripting.GetType().GetMethod("Init").Invoke(IanBrowser.ObjectForScripting, new object[] { arguments[0].GetStringValue() });
                    break;
                case "Load":
                    IanBrowser.ObjectForScripting.GetType().GetMethod("Load").Invoke(IanBrowser.ObjectForScripting, null);
                    break;
                case "UnLoad":
                    IanBrowser.ObjectForScripting.GetType().GetMethod("UnLoad").Invoke(IanBrowser.ObjectForScripting, null);
                    break;
                case "Timeout":
                    IanBrowser.ObjectForScripting.GetType().GetMethod("Timeout").Invoke(IanBrowser.ObjectForScripting, null);
                    break;
                case "Go":
                    IanBrowser.ObjectForScripting.GetType().GetMethod("Go").Invoke(IanBrowser.ObjectForScripting, new object[] { arguments[0].GetStringValue() });
                    break;
                case "Call":
                    IanBrowser.ObjectForScripting.GetType().GetMethod("Call").Invoke(IanBrowser.ObjectForScripting, new object[] { arguments[0].GetStringValue(), arguments[1].GetStringValue() });
                    break;
                case "GoBack":
                    IanBrowser.ObjectForScripting.GetType().GetMethod("GoBack").Invoke(IanBrowser.ObjectForScripting, null);
                    break;
                case "Lock":
                    IanBrowser.ObjectForScripting.GetType().GetMethod("Lock").Invoke(IanBrowser.ObjectForScripting, new object[] { arguments[0].GetStringValue() });
                    break;
            }
            returnValue = CefV8Value.CreateString(name);
            exception = null;
            return true;
        }
    }
}
